package com.itheima.HomeWork;

import java.io.*;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Demo03 {
    public static void main(String[] args) throws Exception {
        List<Hero> list=new ArrayList<>();
        BufferedReader br=new BufferedReader(new FileReader("D:\\黑马线下\\68期\\Java进阶\\课后作业\\day10\\hero.txt", Charset.forName("GBK")));
        String s;
        String head=br.readLine();
        while((s=br.readLine())!=null){
            String[] split = s.split(",+");
            double score=Integer.parseInt(split[1])*0.5+Integer.parseInt(split[2])*0.2+Integer.parseInt(split[3])*0.3;
            list.add(new Hero(split[0],split[1],split[2],split[3],score));
        }

        Collections.sort(list, new Comparator<Hero>() {
            @Override
            public int compare(Hero o1, Hero o2) {
               return Double.compare(o2.getScore(),o1.getScore());
            }
        });

        System.out.println(list);

        BufferedWriter bw=new BufferedWriter(new FileWriter("D:\\黑马线下\\68期\\Java进阶\\课后作业\\day10\\hero1.txt"));
        bw.write(head+"效果");
        bw.newLine();
        for(Hero hero:list){
            bw.write(hero.getName()+" "+hero.getHeart()+" "+hero.getAttack()+" "+hero.getEffect()+" "+hero.getScore());
            bw.newLine();
        }
        br.close();
        bw.close();



    }
}

class Hero{
    private String name;
    private String heart;
    private String attack;
    private String effect;
    private double score;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getHeart() {
        return heart;
    }

    public void setHeart(String heart) {
        this.heart = heart;
    }

    public String getAttack() {
        return attack;
    }

    public void setAttack(String attack) {
        this.attack = attack;
    }

    public String getEffect() {
        return effect;
    }

    public void setEffect(String effect) {
        this.effect = effect;
    }

    public double getScore() {
        return score;
    }

    public void setScore(double score) {
        this.score = score;
    }

    public Hero(String name, String heart, String attack, String effect, double score) {
        this.name = name;
        this.heart = heart;
        this.attack = attack;
        this.effect = effect;
        this.score = score;
    }

    public Hero() {
    }

    @Override
    public String toString() {
        return "Hero{" +
                "name='" + name + '\'' +
                ", heart='" + heart + '\'' +
                ", attack='" + attack + '\'' +
                ", effect='" + effect + '\'' +
                ", score=" + score +
                '}';
    }
}